<template>
  <a-modal title="选择样本" width="65%" v-model:visible="showModal" @ok="handleOk">
    <SuperTable
      :row-config="{ isCurrent: true, isHover: true }"
      :data-request="fetchData"
      :height="400"
      :columns="baseColumns"
      pager
      align="center"
      border
      search
      ref="supertable"
    >
      <template #toolbar> </template>
    </SuperTable>
  </a-modal>
</template>
<script setup lang="tsx">
import SuperTable from '@/framework/components/core/super-table/super-table.vue';
import { VxeGridPropTypes } from 'vxe-table';
import { sampleSearch } from '../api/index';
import { ref, defineEmits } from 'vue';
import { message } from 'ant-design-vue';
const emit = defineEmits(['echo']);
const props = defineProps({
  showModal: { type: Boolean, default: false },
});
let baseColumns: any = [
  {
    title: '编号',
    field: 'originalSerial',
  },
  {
    title: '项目组',
    field: 'projectName',
  },
  {
    title: '样本名称',
    field: 'name',
  },
  {
    title: '采样日期',
    field: 'sampleTime',
    hideInSearch: true,
  },
  {
    title: '采样地点',
    field: 'sampleAddress',
    hideInSearch: true,
  },
  {
    title: '单位',
    field: 'countUnit',
    hideInSearch: true,
    width: 100,
  },
  {
    title: '实验室感染性材料管理负责人',
    field: 'preservUserName',
    hideInSearch: true,
  },
];
const supertable = ref<InstanceType<typeof SuperTable>>();
const fetchData = async (ori: VxeGridPropTypes.ProxyAjaxQueryParams) => {
  const query = {
    pageSize: ori.page.pageSize,
    pageNum: ori.page.currentPage,
    'orderBy[0].field': 'id', // 默认排序字段
    'orderBy[0].order': 'desc', // 默认排序方式
  };
  let queryParam = {
    projectId: '',
    originalSerial: '',
    name: '',
  };
  let { result } = await sampleSearch(queryParam, query);
  return result;
};
const handleOk = () => {
  if (!supertable.value.getCurrentRecord()) return message.warning('未选择数据');
  emit('echo', supertable.value.getCurrentRecord());
};
</script>
<style lang="less" scoped>
::v-deep .ant-card-head {
  display: none;
}
</style>
